import React, { Component } from 'react'
import { Modal, Form } from 'antd';
import { ModalForm } from '../../components'
const WrappedAdvancedSearchForm = Form.create()(ModalForm);
const confirm = Modal.confirm;


export default class AddUserPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            visible: false,
            getFormDataFromAjax: []
        };

        this.formAlerSize = 'small'; //弹出框的大小 只有'large'和'small'两种值 （必须,输错时默认为large）
        this.getFormData = [
            {
                type : 'input',
                showName : '登录用户名',
                name : 'loginName',
                initialValue : '',
                required:'required'  //选填
            },{
                type : 'input',
                showName : '人员姓名',
                name : 'userName',
                initialValue : ''
            },{
                type : 'input',
                showName : '邮箱',
                name : 'email',
                initialValue : ''
            },{
                type : 'input',
                showName : '座机号',
                name : 'phone',
                initialValue : '',
                required:'required'  //选填
            },{
                type : 'input',
                showName : '手机号',
                name : 'mobile',
                initialValue : '',
                required:'required'  //选填
            }
        ];
    }
    //新增用户
    addHandle = () => {
        this.setState({
            visible: true,
        });
        this.getFormData.map( (e) => {
            e.initialValue = ''
        });
    }

    //修改用户
    updateHandle = (userObj) => {
        this.setState({
            visible: true,
        });
        this.getFormData.map( (e) => {
            e.initialValue = userObj[e.name]
        });
    }

    deleteHandle= (loginName) => {
        confirm({
            title: '您确定要删除吗？',
            //content: '',
            onOk() {
                console.log("删除了数据")


            },
            onCancel() {
                console.log("取消了删除操作")
            },
        });


    }


    handleOk = () => {
        this.setState({
            visible: false
        })
    }
    handleCancel = () => {
        this.setState({ visible: false });
    }

    render() {
        const formAlerSize = this.formAlerSize;
        const getFormData = this.getFormData;

        return(
            <Modal
                style={{top:'20px'}}
                visible={this.state.visible}
                title="Title"
                onOk={this.handleOk}
                onCancel={this.handleCancel}
                width={formAlerSize=='large'?'850px':'400px'}
                footer=''
            >

                <WrappedAdvancedSearchForm formAlerSize={formAlerSize}  formUrl="/acitonPage" getFormData={getFormData}  closeBox={this.handleCancel} checkBox={this.handleOk} />

            </Modal>
        )
    }
}